package com.wn.project.web;

import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.Procedure;
import com.wn.project.service.ProcedureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: pms
 * @ClassName ProcedureController
 * @description:
 * @author: LRW
 * @create: 2022-10-25 11:10
 * @Version 1.0
 **/
@RestController
@RequestMapping("/procedure")
public class ProcedureController {

    @Autowired
    private ProcedureService procedureService;

    /***
     * @description: 增加项目流程
     * @param: procedure
     * @return: com.wn.common.ResponseEntity
     * @author Lrw
     * @date: 2022/10/26 20:02
     */
    @PostMapping("/add")
    public ResponseEntity add(@RequestBody Procedure procedure){
        procedureService.add(procedure);
        return ResponseEntity.success;
    }

    /***
     * @description: 删除最后一个流程
     * @param: id
     * @return: com.wn.common.ResponseEntity
     * @author Lrw
     * @date: 2022/10/26 20:19
     */
    @RequestMapping("/delete/{id}")
    public ResponseEntity delete(@PathVariable int id){
        procedureService.deleteById(id);
        return ResponseEntity.success;
    }

    /***
     * @description: 查询项目的所有流程（每页显示15条）
     * @param: projectId currPage
     * @return: com.wn.common.ResponseEntity
     * @author Lrw
     * @date: 2022/10/26 20:26
     */
    @RequestMapping("/list/{projectId}/{currPage}")
    public ResponseEntity list(@PathVariable int projectId,
                               @PathVariable int currPage){
        PageBean<Procedure> pageBean = procedureService.getByProjectId(projectId, currPage);
        return new ResponseEntity("200","ok",pageBean);
    }

    /***
     * @description: 修改项目流程
     * @param: procedure
     * @return: com.wn.common.ResponseEntity
     * @author Lrw
     * @date: 2022/10/26 20:01
     */
    @PostMapping("/update")
    public ResponseEntity update(@RequestBody Procedure procedure){
        procedureService.update(procedure);
        return ResponseEntity.success;
    }

    /***
     * @description: 按id查
     * @param: id
     * @return: com.wn.common.ResponseEntity
     * @author Lrw
     * @date: 2022/10/26 20:19
     */
    @GetMapping("/get")
    public ResponseEntity getById(@PathVariable int id){
        Procedure procedure = procedureService.getById(id);
        return new ResponseEntity("200","ok",procedure);
    }


}
